package main

/*
	你是一个专业的小偷，计划偷窃沿街的房屋。每间房内都藏有一定的现金，影响你偷窃的唯一制约因素就是相邻的房屋装有相互连通的防盗系统，
	如果两间相邻的房屋在同一晚上被小偷闯入，系统会自动报警。
	给定一个代表每个房屋存放金额的非负整数数组，计算你不触动警报装置的情况下，一夜之内能够偷窃到的最高金额
*/

import "fmt"

func rob(nums []int) int{
	chosen := []int{0,0,0,0}
	value := 0
	value = robHelper(nums,0,chosen,value)
	return value
}

func robHelper(nums []int, cur int,chosen []int, value int) int{
	//base case
	if cur>len(nums)-1{
		fmt.Println("base case cur=",cur," value= ",value)
		return value
	}else{
		if cur>0&&chosen[cur-1]==1{
			//前一家偷了
			fmt.Println("rob ",cur-1," and cut",cur)
			return value
		}else {
			//choose-explore
			//un-rob
			fmt.Println("unrob ",cur)
			valueUnRob := robHelper(nums,cur+1,chosen,value)
			fmt.Println("unrob ",cur," and value= ",valueUnRob)
			//rob
			chosen[cur]=1
			value += nums[cur]
			fmt.Println("rob ",cur)
			valueRob := robHelper(nums,cur+1,chosen,value)
			fmt.Println("rob ",cur," and value= ",valueRob)
			//unchoose
			value -= nums[cur]
			chosen[cur]=0
			if valueRob>valueUnRob{
				return valueRob
			}else{
				return valueUnRob
			}
		}
	}
}

func main(){
	nums := []int{1,2,3,1}
	print(rob(nums))
}
